/**
 * 
 */
package com.scpii.universal.service.impl;

import java.lang.Integer;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import javax.annotation.Resource;

import org.springframework.stereotype.Service;

import com.scpii.universal.constant.GenericConstants;
import com.scpii.universal.hibernate.dao.ManageUserDao;
import com.scpii.universal.hibernate.entity.ManageUserTab;
import com.scpii.universal.service.ManageUserService;

/**
 * genericWeb
 * @author weny
 * 2012-7-8下午09:44:41
 */
@Service
public class ManageUserServiceImpl extends BaseServiceImpl<ManageUserTab, Integer> implements
		ManageUserService {
	@Resource
	private ManageUserDao manageUserDao;
	@Resource
	public void setBaseDao(ManageUserDao manageUserDao) {
		super.setBaseDao(manageUserDao);
	}
	
	/**
	 * 根据用户名和密码，进行验证登录
	 * @param userLoginName
	 * @param userPassword
	 * @return
	 * @throws Exception
	 */
	public List<ManageUserTab> manageUserLogin(String userLoginName,String userPassword){
		StringBuffer hql = new StringBuffer("from ManageUserTab u ");
		hql.append("where u.varPassword=:userPassword and u.varLoginName=:userLoginName and u.intDeleteSign=:intDeleteSign");
		Map<String,Object> argsMap = new HashMap<String,Object>();
		argsMap.put("userLoginName", userLoginName);
		argsMap.put("userPassword", userPassword);
		argsMap.put("intDeleteSign", GenericConstants.DELETE_SIGN_EXIST);
		return manageUserDao.hqlGetList(hql.toString(), argsMap);
	}

	/* (non-Javadoc)
	 * @see com.scpii.universal.service.ManageUserService#checkUserName(java.lang.String)
	 */
	@Override
	public List<ManageUserTab> checkUserName(String username) {
		StringBuffer hql = new StringBuffer("from ManageUserTab u ");
		hql.append("where  u.varLoginName=:userLoginName ");
		Map<String,Object> argsMap = new HashMap<String,Object>();
		argsMap.put("userLoginName", username);
		return manageUserDao.hqlGetList(hql.toString(), argsMap);
	}

	@Override
	public List<ManageUserTab> getUsersByLoginName(String loginName) {
		StringBuffer hql = new StringBuffer("from ManageUserTab u ");
		hql.append("where  u.varLoginName like '%"+loginName+"%' ");
		hql.append("and  u.intDeleteSign=0 ");
		hql.append("order by u.varPaireKey ");
		return manageUserDao.hqlGetList(hql.toString(), null);
	}
}
